import com.southminority.ethnic.EthnicMinorityApplication;
import com.southminority.ethnic.config.JacksonConfig;
import com.southminority.ethnic.enums.RedisKeyEnum;
import com.southminority.ethnic.pojo.User;
import com.southminority.ethnic.service.redis.RedisService;
import com.southminority.ethnic.service.user.UserService;
import com.southminority.ethnic.until.AesUtil;
import com.southminority.ethnic.until.JsonUtil;
import io.swagger.v3.core.util.Json;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.concurrent.TimeUnit;

@SpringBootTest(classes = EthnicMinorityApplication.class)
public class test {
    @Autowired
    private RedisService redisService;
    @Test
    public void test1(){
        redisService.redisSetValue("test","test",20L, TimeUnit.SECONDS);
    }
    @Test
    public void test2(){
       String s= (String)redisService.redisGetValue("test");
        System.out.println(s);
    }


    String token3="2";
    @Test
    public void test3_1(){
        try {
            User user=new User();
            user.setId(1L);
            user.setUsername("user");
            user.setPassword("123456");
            String Json= JsonUtil.toJson(user);
            Boolean b=redisService.redisSetValue(
                    RedisKeyEnum.USER_TOKEN.getKeyPrefix()+token3,
                    Json,
                    RedisKeyEnum.USER_TOKEN.getExpireTime(),
                    RedisKeyEnum.USER_TOKEN.getTimeUnit()
            );
            System.out.println(b);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
    @Test
    public void test3_2(){
        try {
            Boolean b=redisService.expire(
                    RedisKeyEnum.USER_TOKEN.getKeyPrefix()+token3,
                    RedisKeyEnum.USER_TOKEN.getExpireTime(),
                    RedisKeyEnum.USER_TOKEN.getTimeUnit()
            );
            System.out.println(b);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
    @Test
    public void test3(){
        Long l= (Long)redisService.redisGetExpireTime(
                RedisKeyEnum.USER_TOKEN.getKeyPrefix()+token3,
                //RedisKeyEnum.USER_TOKEN.getTimeUnit()
                TimeUnit.MINUTES
        );
        System.out.println(l);
    }
    @Test
    public void test4(){
        String s= (String)redisService.redisGetValue(RedisKeyEnum.USER_TOKEN.getKeyPrefix()+token3);
        System.out.println(s);
    }
    @Test
    public void test5(){
        Boolean b= redisService.redisDelete(RedisKeyEnum.USER_TOKEN.getKeyPrefix()+token3);
        System.out.println(b);
    }
    @Test
    public void test6(){
        try{
            String s="123456";
            System.out.println("加密前："+s);
            String s1= AesUtil.encryptStrAES(s);
            System.out.println("加密后："+s1);
            String s2= AesUtil.decryptStrAES(s1);
            System.out.println("解密后："+s2);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Autowired
    private UserService userService;

    @Test
    public void test7(){
        try{
            String emall="admin1@qq.com";
            String s="123456";

            User b=userService.login(emall,s);
            System.out.println(b.toString());
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
